package de.fhb.itunes.controller.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.connector.Request;

import com.sun.crypto.provider.RSACipher;

import de.fhb.itunes.manager.AlbumSearch.AlbumList;
import de.fhb.itunes.manager.AlbumSearch.AlbumListInterface;
import de.fhb.itunes.repository.data.Album_VO;

/**
 * Servlet implementation class AlbumSearchView
 */
@WebServlet("/AlbumSearch")
public class AlbumSearchView extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
	

	AlbumListInterface albumList = new AlbumList();
	
	
    public AlbumSearchView() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		List<Album_VO> resultSet;
		if(request.getParameter("search") != null){
			resultSet = albumList.getAlbums((String)request.getParameter("search"));
			request.setAttribute("resultSet", resultSet);
			request.setAttribute("success", true);
		}
		else
		{
			resultSet = albumList.getAllAlbums();
			request.setAttribute("resultSet", resultSet);
			request.setAttribute("success", true);
			
		}
		
		
		RequestDispatcher req = request.getRequestDispatcher("AlbumSearchView.jsp");
		req.forward(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
